from PIL import Image
import os
from pytesseract import image_to_string
memedir = '/Users/hadrien/Desktop/ML/neurchidered/lowquality/'

# ocr = open("tmp/ocr.neurchidered.txt", 'wb', 0)
ocr = open("tmp/ocr.neurchidered.langfra.txt", 'wb', 0)
for image in os.listdir(memedir):
    # line = '"'+image+'":\n'+image_to_string(Image.open(memedir+image))+'\n'
    line = '"'+image+'":\n' + \
        image_to_string(Image.open(memedir+image), lang='fra')+'\n'
    print(line)
    ocr.write(line.encode('utf-8'))
ocr.close()
